package com.liumapp.auth.zuul.company.api;

import com.google.common.collect.Lists;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 * Created by liumapp on 3/5/18 3:21 PM.
 * E-mail:liumapp.com@gmail.com
 * home-page:http://www.liumapp.com
 */
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"com.liumapp.auth.zuul.company.api"})
@EnableSwagger2
public class Company {

    public static void main(String[] args) {
        SpringApplication.run(Company.class , args);
    }

    @Bean
    public Docket createRestApi(){

        /***
         * 设置header 属性
         */
        ParameterBuilder uid = new ParameterBuilder();
        uid.name("access_token").description("access_token").modelRef(new ModelRef("string")).parameterType("query").required(true).build();

        List<Parameter> pars = Lists.newArrayList(uid.build()) ;

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("OpenApi Platform API Document")
                        .description("spring boot restful")
                        .version("1.0")
                        .contact(new Contact("laiyujun", "https://blog.csdn.net/Ryan200909", "laiyujun@vip.qq.com"))
                        .build()
                )
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.liumapp.auth.zuul.company.api.controller"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(pars);
    }
}
